package com.bike.bikeserver.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import com.bike.bikeserver.common.annotation.OperationLog;
import com.bike.bikeserver.common.core.domain.CommonResult;
import com.bike.bikeserver.domain.SysRole;
import com.bike.bikeserver.service.impl.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.bike.bikeserver.constant.Constants.USER_RIGHT_ALL;

/**
 * @version 1.0
 * @Author ZZX
 * @Date 2023/7/21 13:36
 */
@RestController
@RequestMapping("sys/system")
public class SysRoleController
{
    @Autowired
    SysRoleService sysRoleService;

    /**
     * 获取所有系统角色
     *
     * @return
     */
    @SaCheckPermission(value = {USER_RIGHT_ALL}, mode = SaMode.OR)
    @GetMapping("getSysRoleList")
    public CommonResult getSysRoleList()
    {
        return sysRoleService.getSysRoleList();
    }

    /**
     * 根据用户来源或用户权限获取角色权限信息
     *
     * @param sth
     * @param info
     * @return
     */
    @SaCheckPermission(value = {USER_RIGHT_ALL}, mode = SaMode.OR)
    @GetMapping("getRoleBySth")
    public CommonResult getRoleBySth(@RequestParam("sth") String sth, @RequestParam("info") String info)
    {
        return sysRoleService.getRoleBySth(sth, info);
    }

    /**
     * 根据id修改角色权限
     *
     * @param sysRole
     * @return
     */
    @SaCheckPermission(value = {USER_RIGHT_ALL}, mode = SaMode.OR)
    @OperationLog("根据id修改角色权限:sys_role")
    @PutMapping("updateRoleRightById")
    public CommonResult updateRoleRightById(@RequestBody SysRole sysRole)
    {
        return sysRoleService.updateRoleRightById(sysRole);
    }
}
